package com.shensi.appCollect.enums;

import java.util.HashMap;

/**
 * @date 2023/10/17
 */
public enum ElectronCardType {
    GENERIC("0","通用"),
    GAS("1","汽油"),
    DIESEL("2","柴油"),
    LNG("3","LNG"),
    CNG("4","CNG"),
    RETURNCASH("5","返利账户"),
    ;

    private final String key;
    private final String name;

    ElectronCardType(String key, String name) {
        this.key = key;
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public String getName() {
        return name;
    }

    private static HashMap<String, ElectronCardType> keyMap;

    public static ElectronCardType getByKey(String key){
        if (keyMap == null) {
            HashMap<String, ElectronCardType> map = new HashMap<>();
            for (ElectronCardType value : ElectronCardType.values()) {
                map.put(value.getKey(),value);
            }
            keyMap = map;
        }
        return keyMap.get(key);
    }

    public static ElectronCardType getByKey(String key,ElectronCardType def){
        ElectronCardType type = getByKey(key);
        return type == null ? def : type;
    }
}
